package com.yx.pc.api.controller;

import com.yx.common.utils.R;
import com.yx.modules.api.annotation.AuthIgnore;
import com.yx.utils.FastDFSClientWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件上传控制器
 */
@RestController
@RequestMapping("/pc/api/upload")
public class PcFileUpLoadController {

    @Autowired
    private FastDFSClientWrapper fds;
    /**
     * 上传
     *
     * @return
     */
    @AuthIgnore
    @PostMapping("up")
    public R upload(MultipartFile file) {
        String url = null;
        try {
            url = fds.uploadFile(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.ok().put("url", url);
    }

    /**
     * 删除
     *
     * @return
     */
    @AuthIgnore
    @PostMapping("delete")
    public R delete(String url) {
        fds.deleteFile(url);
        return R.ok();
    }


}
